package constant

import (
	"os"
	"path/filepath"
	"strings"

	"gitlab.local/golibrary/utils"
)

const (
	PamConf = "/etc/pam_conf"
)

func ReadFileLine(pfile string) []string {
	result := make([]string, 0)
	b, err := os.ReadFile(pfile)
	if err == nil {
		res := strings.Split(string(b), "\n")
		if len(res) > 0 {
			for _, name := range res {
				name = strings.TrimSpace(name)
				if name != "" {
					result = append(result, name)
				}
			}
		}

	}
	return result
}

// WriteToFile users example: []string{"uzqw", "admin", "user1"}
// WriteTo location example: /etc/pam_conf/SMB
func WriteUsersToFile(appId string, users []string) {
	result := ""
	for _, user := range users {
		result = result + user + "\n"
	}
	_, _ = utils.WriteFile(filepath.Join(PamConf, appId), result)
}
